package com.ohs.dal.dao.impl;

import java.util.List;

import com.ohs.dal.dao.ScheduleDAO;
import com.ohs.dal.model.Schedule;
import com.ohs.dal.model.ScheduleId;

public class ScheduleDAOImpl extends AbstractDAOImpl<Schedule> implements ScheduleDAO {

	public void add(Schedule scheduleId) {
		getHibernateTemplate().save(scheduleId);
	}

	public List<Schedule> list() {
		return getHibernateTemplate().find("from " + Schedule.class.getName());
	}

	public Schedule get(ScheduleId scheduleId) {
		return (Schedule) getHibernateTemplate().get(Schedule.class, scheduleId);
	}

	public List<Schedule> findByRoom(long roomId) {
		return getHibernateTemplate().find("from Schedule s where s.id.roomId = " + roomId);
	}

	public boolean isSetupSchedule(String username) {
		return (getHibernateTemplate().find("from Schedule s where s.id.roomId in " +
				"(select r.roomId from Room r where r.location.account.username = '" + username + "')").size() > 0);
	}

}
